import { Navigator, View, Button, Text, Block } from '@tarojs/components'
import { useCallback, useEffect, useState } from 'react';
import Taro from '@tarojs/taro'
import { useSelector, useDispatch } from 'react-redux'

import { getMyCompanyInfo } from '../../../service/data'

import Header from '../../../components/public/header/Header';
import { PeopleTemp } from './PeopleTemp'
import { GovTemp } from './GovTemp'


function Usercenter() {
  const userInfo = useSelector(state => state.userInfo)

  const {
    __userInfo,
    __isBindStaff,
    token,
    __authorizePhoneStatus
  } = userInfo

  const [myUnitList, setMyUnitList] = useState([])
  const m = useCallback(async (isFristAuth = 0) => {
    if (token) {
      const r = await getMyCompanyInfo()
      if (isFristAuth && r.length === 0) {
        Taro.reLaunch({
          url: '/subs/instruction/pages/my-company/my-company'
        })
      }
      if (isFristAuth && r.length > 1) {
        Taro.navigateTo({
          url: '/subs/instruction/pages/my-company/my-company'
        })
        setMyUnitList(r)
      }
    }
  }, [token])
  useEffect(() => {
    m()
  }, [m, token])

  const [] = useState()

  return (
    <Block>
      <Header title={__userInfo.gov ? '公文包' : '个人中心'} showUserAvatar={false} />
      {__isBindStaff} dsds
      {__userInfo.gov && __isBindStaff ? (<GovTemp />) : (<PeopleTemp userInfo={userInfo} myUnitList={myUnitList} />)}

    </Block>
  )
}

export default Usercenter